﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Collections.ObjectModel;

namespace EasyAR.Model
{
    public class CameraModel
    {
        public CaptureSource Camera { get; private set; }

        public void InitializeCameraAsDefault()
        {
            InitializeCamera(CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice());
        }

        public void InitializeCamera(VideoCaptureDevice device)
        {
            Camera = new CaptureSource();
            Camera.VideoCaptureDevice = device;
            Camera.VideoCaptureDevice.DesiredFormat = SupportVideoFormat[0];
        }

        public ReadOnlyCollection<VideoCaptureDevice> AvailableVideoCamera { get{return CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();}}

        public VideoFormat VideoFormat { get { return Camera.VideoCaptureDevice.DesiredFormat; } set { Camera.VideoCaptureDevice.DesiredFormat = value; } }

        public ReadOnlyCollection<VideoFormat> SupportVideoFormat { get{ return Camera.VideoCaptureDevice.SupportedFormats;}}

        public void StartCamera()
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                Camera.Start();
            }
        }

        public void StopCamera()
        {
            Camera.Stop();
        }
    }
}